import { ref } from 'vue'

export const useRequest = (loading = false) => {
    const cloading = ref(loading)

    const request = function(promise){
        cloading.value = true

        return new Promise((resolve, reject) => {
            promise.then((res) => {
                cloading.value = false
                resolve(res)
            }).catch(err => {
                cloading.value = false
                reject(err)
            })
        })
    }

    return {
        loading: cloading,
        request
    }
}